#include <iostream>
#include <string>
#include <vector>

using namespace std;

// https://leetcode.cn/problems/longest-substring-without-repeating-characters/?envType=study-plan-v2&envId=top-100-liked

class Solution
{
public:
    int lengthOfLongestSubstring(string s)
    {
        int ans = 0;
        int left = 0;
        vector<int> alph(128);
        for (int i = 0; i < s.size(); i++)
        {
            alph[s[i]]++;
            while (alph[s[i]] > 1)
            {
                alph[s[left++]]--;
            }
            ans = max(ans, i - left + 1);
        }
        return ans;
    }
};